import 'package:boss/common/common.dart';

import 'package:boss/main.dart';

import 'package:boss/provider/account_provider.dart';
import 'package:boss/provider/home_provider.dart';
import 'package:boss/provider/staff_provider.dart';
import 'package:boss/provider/store_message_provider.dart';
import 'package:boss/ui/page/login/login_page.dart';
import 'package:boss/ui/page/login/model/cache_user.dart';
import 'package:boss/ui/page/personalSettings/widget/personal_setting_list_title_list.dart';
import 'package:boss/ui/page/personalSettings/widget/personal_setting_login_out_btn.dart';
import 'package:boss/ui/page/personalSettings/widget/personal_setting_user_card.dart';
import 'package:boss/ui/widget/alert/alert.dart';
import 'package:boss/ui/widget/loading/loading.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PersonalSettingBrowser extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      padding: EdgeInsets.symmetric(horizontal: 30.w),
      child: Column(
        children: <Widget>[
          PersonalSettingUserCard(),
          PersonalSettingListTitleList(),
          PersonalSettingLoginOutBtn(
            onTap: () {
              showAlert(
                context,
                content: '退出后不会删除任何历史 数据，下次登录依然可以使用本账号。',
                onCancel: (context) {
                  Navigator.pop(context);
                },
                onConfirm: (ctx) async {
                  showLoadingToast();
                  await api.logout(Constant.uuid);
                  var staffProvider = Provider.of<StaffProvider>(context, listen: false);
                  staffProvider.clearData();

                  var accountProvider = Provider.of<AccountProvider>(context, listen: false);
                  accountProvider.clearData();

                  var storeMessageProvider = Provider.of<StoreMessageProvider>(context, listen: false);
                  storeMessageProvider.clearData();

                  var homeProvider = Provider.of<HomeProvider>(context, listen: false);
                  homeProvider.clearData();

                  //清除登录用户
                  CacheUser c = CacheUser.getCacheUser();
                  c.loginUser.isExpired = true;
                  CacheUser.cacheUser(c);
                  hideLoadingToast();

                  Navigator.pushNamedAndRemoveUntil(context, LoginPage.pageName, (route) => false);
                },
              );
            },
          ),
        ],
      ),
    );
  }
}
